﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BasketballAI
{
    public partial class BBSetting : Form
    {
        public BBSetting()
        {
            InitializeComponent();
        }

        private void BBSetting_Load(object sender, EventArgs e)
        {
            //setting  trackBars. 
            this.trackBar11.Maximum = Properties.Settings.Default.maxSpeedPlayer;
            this.trackBar11.Minimum = Properties.Settings.Default.minSpeedPlayer;
            this.trackBar11.Value = (Properties.Settings.Default.maxSpeedPlayer - Properties.Settings.Default.minSpeedPlayer) / 2 + Properties.Settings.Default.minSpeedPlayer;
            this.trackBar11.TickFrequency = Properties.Settings.Default.frequency;

            this.trackBar12.Maximum = Properties.Settings.Default.maxSpeedPlayer;
            this.trackBar12.Minimum = Properties.Settings.Default.minSpeedPlayer;
            this.trackBar12.TickFrequency = Properties.Settings.Default.frequency;
            this.trackBar12.Value = Properties.Settings.Default.minSpeedPlayer;

            this.trackBar13.Maximum = Properties.Settings.Default.maxSpeedPlayer;
            this.trackBar13.Minimum = Properties.Settings.Default.minSpeedPlayer;
            this.trackBar13.TickFrequency = Properties.Settings.Default.frequency;
            this.trackBar13.Value = Properties.Settings.Default.minSpeedPlayer;

            this.trackBar21.Maximum = Properties.Settings.Default.maxSpeedPlayer;
            this.trackBar21.Minimum = Properties.Settings.Default.minSpeedPlayer;
            this.trackBar21.TickFrequency = Properties.Settings.Default.frequency;
            this.trackBar21.Value = (Properties.Settings.Default.maxSpeedPlayer - Properties.Settings.Default.minSpeedPlayer) / 2 + Properties.Settings.Default.minSpeedPlayer;

            this.trackBar22.Maximum = Properties.Settings.Default.maxSpeedPlayer;
            this.trackBar22.Minimum = Properties.Settings.Default.minSpeedPlayer;
            this.trackBar22.TickFrequency = Properties.Settings.Default.frequency;
            this.trackBar22.Value = Properties.Settings.Default.minSpeedPlayer;

            this.trackBar23.Maximum = Properties.Settings.Default.maxSpeedPlayer;
            this.trackBar23.Minimum = Properties.Settings.Default.minSpeedPlayer;
            this.trackBar23.TickFrequency = Properties.Settings.Default.frequency;
            this.trackBar23.Value = Properties.Settings.Default.minSpeedPlayer;

            txtPlayer11.Text = Properties.Settings.Default.Team1PlayerNames.Split(',')[0];
            txtPlayer12.Text = Properties.Settings.Default.Team1PlayerNames.Split(',')[1];
            txtPlayer13.Text = Properties.Settings.Default.Team1PlayerNames.Split(',')[2];

            txtPlayer21.Text = Properties.Settings.Default.Team2PlayerNames.Split(',')[0];
            txtPlayer22.Text = Properties.Settings.Default.Team2PlayerNames.Split(',')[1];
            txtPlayer23.Text = Properties.Settings.Default.Team2PlayerNames.Split(',')[2];
        }

        private void btnPlay_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.timerPlayer11Ms = this.trackBar11.Value;
            Properties.Settings.Default.timerPlayer12Ms = this.trackBar12.Value;
            Properties.Settings.Default.timerPlayer13Ms = this.trackBar13.Value;
            Properties.Settings.Default.timerPlayer21Ms = this.trackBar21.Value;
            Properties.Settings.Default.timerPlayer22Ms = this.trackBar22.Value;
            Properties.Settings.Default.timerPlayer23Ms = this.trackBar23.Value;

            Properties.Settings.Default.Team1PlayerNames = txtPlayer11.Text + "," + txtPlayer12.Text + "," + txtPlayer13.Text;
            Properties.Settings.Default.Team2PlayerNames = txtPlayer21.Text + "," + txtPlayer22.Text + "," + txtPlayer23.Text;

            this.Visible = false;
            using (Form form = new BBGame())
            {
                form.ShowDialog();
            }
            this.Visible = true;  
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
